<!--
 * @Author: @yzcheng
 * @Date: 2021-03-01 11:12:00
 * @Version: 1.0
 * @LastEditors: @yzcheng
 * @Description: 
 * @LastEditTime: 2021-03-12 10:42:46
-->
<template>
  <el-dialog
    :title="$t('flowDefine.classification')"
    width="400px"
    destroy-on-close
    :model-value="visible"
  >
    <div class="define_selectTree">
      <div class="define_form_class">
        <el-input size="small" width="100%" v-model="filterText"></el-input>
      </div>
      <div class="define_content">
        <el-tree
          :data="treeData"
          v-model="type"
          node-key="id"
          default-expand-all
          :filter-node-method="filterNode"
          @node-click="changeFlowType"
          :props="defaultProps"
          ref="tree"
        >
        </el-tree>
      </div>
      <div class="define_footer">
        <el-button @click="submit" type="primary">
          <i class="el-icon-check"></i>{{ $t("common.ok") }}</el-button
        >
        <el-button @click="clear" type="danger">
          <i class="el-icon-check"></i>{{ $t("common.clear") }}</el-button
        >
        <el-button @click="$emit('down')">
          <i class="el-icon-close"></i>{{ $t("common.close") }}</el-button
        >
      </div>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    treeData: {
      type: Array,
      default: function () {
        return [];
      },
    },
    visible: {
      type: Boolean,
      default: function () {
        return false;
      },
    },
  },
  data() {
    return {
      rules: [],
      type: "",
      filterText: "",
      defaultProps: {
        children: "children",
        label: "name",
      },
    };
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
  methods: {
    // currentChange() {},
    changeFlowType(item) {
      this.type = item;
    },
    submit() {
      this.$emit("submit", this.type);
    },
    clear() {
      this.$emit("submit", "");
    },
    filterNode(value, data) {
      if (!value) return true;
      return data.name.indexOf(value) !== -1;
    },
  },
};
</script>

<style lang="scss" scoped>
.define_form_class,
.define_content {
  padding: 0 20px;
}
.define_content {
  overflow: auto;
  min-height: 300px;
}
.define_footer {
  display: flex;
  justify-content: space-around;
}
</style>
<style  >
.define_form_class .el-input {
  width: 90%;
}
</style>